load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS", "MATERIAL_TESTING_ENTRYPOINTS")
load("//tools:defaults.bzl", "ts_project")
load("//tools/dgeni:index.bzl", "dgeni_api_docs")

package(default_visibility = ["//visibility:public"])

cdkApiEntryPoints = CDK_ENTRYPOINTS

materialApiEntryPoints = MATERIAL_ENTRYPOINTS + MATERIAL_TESTING_ENTRYPOINTS

# List that contains all source files that need to be processed by Dgeni.
apiSourceFiles = ["//src/cdk/%s:source-files" % name for name in cdkApiEntryPoints] + \
                 ["//src/material/%s:source-files" % name for name in materialApiEntryPoints]

exports_files([
    "bazel-tsconfig-build.json",
    "bazel-tsconfig-test.json",
    "README.md",
])

copy_to_bin(
    name = "package_json",
    srcs = ["package.json"],
)

js_library(
    name = "esbuild-linked-config",
    srcs = ["esbuild-linked.config.mjs"],
)

dgeni_api_docs(
    name = "api-docs",
    srcs = apiSourceFiles + [
        # Add all Angular packages to the sources because some Material exports use
        # Angular exports and these should not cause any warnings when Dgeni uses the
        # type checker to parse our TypeScript sources.
        "//:node_modules/@angular/core",
        "//:node_modules/@angular/common",
        "//:node_modules/@angular/forms",
        "//:node_modules/@angular/platform-browser",
    ],
    entry_points = {
        "cdk": cdkApiEntryPoints,
        "material": materialApiEntryPoints,
    },
    tags = ["docs-package"],
)

ts_project(
    name = "dev_mode_types",
    srcs = ["dev-mode-types.d.ts"],
)

# TODO(devversion): Look into a replacement.
#ts_config(
#    name = "tsec_config",
#    src = "tsconfig-tsec.json",
#    deps = [
#        ":bazel-tsconfig-build.json",
#        "//goldens:tsec-exemption.json",
#    ],
#)

ts_config(
    name = "build-tsconfig",
    src = "bazel-tsconfig-build.json",
    deps = [
        "//:node_modules/tslib",
    ],
)

ts_config(
    name = "test-tsconfig",
    src = "bazel-tsconfig-test.json",
    deps = [
        ":build-tsconfig",
        "//:node_modules/@types/jasmine",
    ],
)
